﻿using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using FunctionalCLR.Shell;

namespace Zove.Test
{
    [TestFixture]
    public class ListTests : AbstractTests
    {
        [Test]
        public void NewList()
        {
            IContext cnt = Execute("a=[1,2,3]");

            object value = cnt.GetVariable("a");
            Assert.IsInstanceOf(typeof(List<object>), value);

            List<object> lst = value as List<object>;
            Assert.AreEqual(3, lst.Count);
            Assert.AreEqual(1, Convert.ToDouble(lst[0]));
            Assert.AreEqual(2, Convert.ToDouble(lst[1]));
            Assert.AreEqual(3, Convert.ToDouble(lst[2]));
        }

        [Test]
        public void JoinList()
        {
            IContext cnt = Execute(
                "a=[1,2,3];b=[4,5,6];c=join(a,b);");

            object value = cnt.GetVariable("c");
            Assert.IsInstanceOf(
                typeof(List<object>), value);

            List<object> lst = value as List<object>;
            Assert.AreEqual(6, lst.Count);
            Assert.AreEqual(1, Convert.ToDouble(lst[0]));
            Assert.AreEqual(2, Convert.ToDouble(lst[1]));
            Assert.AreEqual(4, Convert.ToDouble(lst[3]));
        }

        [Test]
        public void TestPick()
        {
            IContext cnt = Execute(
                "a=[1,2,3];b=pick(a, 2);");

            double value = Convert.ToDouble(
                cnt.GetVariable("b"));
            Assert.AreEqual(3, value);
        }

        [Test]
        public void TestUnion()
        {
        }
    }
}
